<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取可用的加密算法</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.openssl-get-cipher-methods" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_get_cipher_methods</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7)</p><p class="refpurpose"><span class="refname">openssl_get_cipher_methods</span> &mdash; <span class="dc-title">获取可用的加密算法</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.openssl-get-cipher-methods-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_get_cipher_methods</strong></span>
    ([ <span class="methodparam"><span class="type">bool</span> <code class="parameter">$aliases</code><span class="initializer"> = false</span></span>
  ] ) : <span class="type">array</span></div>

  <p class="para rdfs-comment">
   获取可用的加密算法的列表。
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-get-cipher-methods-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">aliases</code></dt>

     <dd>

      <p class="para">
       如果密码别名应该包含在返回的<span class="type"><a href="language.types.array.html" class="type array">array</a></span>中，则设置为 <strong><code>TRUE</code></strong>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-get-cipher-methods-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   一个包含可用加密算法的<span class="type"><a href="language.types.array.html" class="type array">array</a></span>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-get-cipher-methods-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-934">
    <p><strong>Example #1 <span class="function"><strong>openssl_get_cipher_methods()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     展示了哪些加密算法能被找到，哪些别名可用。
    </p></div>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$ciphers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_get_cipher_methods</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$ciphers_and_aliases&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_get_cipher_methods</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$cipher_aliases&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_diff</span><span style="color: #007700">(</span><span style="color: #0000BB">$ciphers_and_aliases</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//ECB&nbsp;mode&nbsp;should&nbsp;be&nbsp;avoided<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$n</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$n</span><span style="color: #007700">,</span><span style="color: #DD0000">"ecb"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /><br /></span><span style="color: #FF8000">//At&nbsp;least&nbsp;as&nbsp;early&nbsp;as&nbsp;Aug&nbsp;2016,&nbsp;Openssl&nbsp;declared&nbsp;the&nbsp;following&nbsp;weak:&nbsp;RC2,&nbsp;RC4,&nbsp;DES,&nbsp;3DES,&nbsp;MD5&nbsp;based<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"des"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"rc2"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"rc4"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"md5"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$cipher_aliases&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(</span><span style="color: #0000BB">$cipher_aliases</span><span style="color: #007700">,function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"des"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$cipher_aliases&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(</span><span style="color: #0000BB">$cipher_aliases</span><span style="color: #007700">,function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"rc2"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$cipher_aliases</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; AES-128-CBC
    [1] =&gt; AES-128-CFB
    [2] =&gt; AES-128-CFB1
    [3] =&gt; AES-128-CFB8
    [5] =&gt; AES-128-OFB
    [6] =&gt; AES-192-CBC
    [7] =&gt; AES-192-CFB
    [8] =&gt; AES-192-CFB1
    [9] =&gt; AES-192-CFB8
    [11] =&gt; AES-192-OFB
    [12] =&gt; AES-256-CBC
    [13] =&gt; AES-256-CFB
    [14] =&gt; AES-256-CFB1
    [15] =&gt; AES-256-CFB8
    [17] =&gt; AES-256-OFB
    [18] =&gt; BF-CBC
    [19] =&gt; BF-CFB
    [21] =&gt; BF-OFB
    [22] =&gt; CAST5-CBC
    [23] =&gt; CAST5-CFB
    [25] =&gt; CAST5-OFB
    [41] =&gt; IDEA-CBC
    [42] =&gt; IDEA-CFB
    [44] =&gt; IDEA-OFB
    [53] =&gt; aes-128-cbc
    [54] =&gt; aes-128-cfb
    [55] =&gt; aes-128-cfb1
    [56] =&gt; aes-128-cfb8
    [58] =&gt; aes-128-ofb
    [59] =&gt; aes-192-cbc
    [60] =&gt; aes-192-cfb
    [61] =&gt; aes-192-cfb1
    [62] =&gt; aes-192-cfb8
    [64] =&gt; aes-192-ofb
    [65] =&gt; aes-256-cbc
    [66] =&gt; aes-256-cfb
    [67] =&gt; aes-256-cfb1
    [68] =&gt; aes-256-cfb8
    [70] =&gt; aes-256-ofb
    [71] =&gt; bf-cbc
    [72] =&gt; bf-cfb
    [74] =&gt; bf-ofb
    [75] =&gt; cast5-cbc
    [76] =&gt; cast5-cfb
    [78] =&gt; cast5-ofb
    [94] =&gt; idea-cbc
    [95] =&gt; idea-cfb
    [97] =&gt; idea-ofb
)
Array
(
    [18] =&gt; AES128
    [19] =&gt; AES192
    [20] =&gt; AES256
    [21] =&gt; BF
    [26] =&gt; CAST
    [27] =&gt; CAST-cbc
    [50] =&gt; IDEA
    [82] =&gt; aes128
    [83] =&gt; aes192
    [84] =&gt; aes256
    [85] =&gt; bf
    [90] =&gt; blowfish
    [91] =&gt; cast
    [92] =&gt; cast-cbc
    [115] =&gt; idea
)

</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.openssl-get-cipher-methods-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="openssl_get_md_methods.html" class="function" rel="rdfs-seeAlso">openssl_get_md_methods()</a> - 获取可用的摘要算法</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>